using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCT.Framework;
using System.Data;
using System.Data.Common;
using NCT.Framework.Database;

namespace VISS.API.Users {
	public class _TmpEmailDA {

        private const string SP_Insert = "dbo.[_TmpEmail_Insert]";
        private const string SP_GetAll = "dbo.[_TmpEmail_GetAll]";

		public static _TmpEmailEnt CreateFromReader(IDataReader reader) {
			_TmpEmailEnt item = new _TmpEmailEnt();
			item.ID = ConvertUtils.ToLong(reader["ID"]);
			item.Email = ConvertUtils.ToString(reader["Email"]);
			return item;
		}

        public static void Insert(_TmpEmailEnt item) {
            Database db = Database.CreateDatabase(ConfigInfo.ConnectionName);
            using (DbCommand cmd = db.CreateStoredCommand(SP_Insert)) {
                db.AddParameter(cmd, "Email", item.Email);

                db.ExecuteNonQuery(cmd);

            }
        }

        public static List<_TmpEmailEnt> GetAll(_TmpEmailEnt item) {
            List<_TmpEmailEnt> result = new List<_TmpEmailEnt>();
            Database db = Database.CreateDatabase(ConfigInfo.ConnectionName);
            using (DbCommand cmd = db.CreateStoredCommand(SP_GetAll)) {
                using (IDataReader reader = db.ExecuteReader(cmd)) {
                    while (reader.Read()) {
                        result.Add(CreateFromReader(reader));
                    }
                }
            }
            return result;
        }

	}
}